<template>
  <div class="app-container">
    <el-form :model="goodsDetail" ref="queryForm" size="small" :inline="true" label-width="110px">

      <el-row>
        <h3>基础信息</h3>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="商品名称">
            <span>{{this.goodsDetail.name}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="商品类型">
            <span v-if="goodsDetail.goodstype==='room'">房间</span>
            <span v-if="goodsDetail.goodstype==='dish'">套餐</span>
            <span v-if="goodsDetail.goodstype==='entertainment'">娱乐项目</span>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="商品状态">
            <span v-if="goodsDetail.status===2">新建</span>
            <span v-if="goodsDetail.status===3">审核通过</span>
            <span v-if="goodsDetail.status===4">审核不通过</span>
            <span v-if="goodsDetail.status===5">已下架</span>
            <span v-if="goodsDetail.status===7">已删除</span>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="销售状态">
            <span v-if="goodsDetail.sellstatus==='soldOut'">已下架</span>
            <span v-if="goodsDetail.status!=='soldOut'">已上架</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6" v-if="goodsDetail.nomaterial==='Y'">
          <el-form-item label="包工不包料价格">
            <span>{{goodsDetail.nomaterialprice}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="goodsDetail.withmaterial==='Y'">
          <el-form-item label="包工包料价格" v-if="goodsDetail.goodstype==='dish'">
            <span>{{goodsDetail.withmaterialprice}}</span>
          </el-form-item>
          <el-form-item label="销售价格" v-if="goodsDetail.goodstype==='room'">
            <span>{{goodsDetail.withmaterialprice}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <h3>商品图片</h3>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="商品封面" v-if="goodsDetail.defaultimage.length >0">
            <image-preview :src="goodsDetail.defaultimage" :width="120" :height="120" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col>
          <el-form-item label="商品相册" v-if="goodsImageList && goodsImageList.length >0">
            <div  class="image_div">
              <div v-for="imageItem in goodsImageList" class="image_item">
                <image-preview :src="imageItem.name" :width="120" :height="120"/>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row v-if="goodsParamsList && goodsParamsList.length>0">
        <h3>菜品列表</h3>
      </el-row>
      <el-table v-loading="loading" :data="goodsParamsList" v-if="goodsParamsList && goodsParamsList.length>0">
        <el-table-column label="类型" align="center" prop="paramsname" width="80" />
        <el-table-column label="名称" align="center" prop="paramsvalue" width="300" />
      </el-table>
    </el-form>

  </div>
</template>

<style>
  .image_div{
    display: flex;
    flex-wrap: wrap;
  }

  .image_item{
    display: flex;
    align-items: center;
    justify-content: center;
    width: 150px;
    height: 150px;
  }
</style>
<script>
import { goodsDetail} from "@/api/smy/mallGoods";

export default {
  name: "Goods",
  data() {
    return {
      goodsId:'',
      goodsDetail:{},
      goodsImageList:[],
      goodsParamsList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      statusList:[
        {value: '1', label: '待上架'},
        {value: '2', label: '新建'},
        {value: '3', label: '审核通过'},
        {value: '4', label: '审核不通过'},
        {value: '5', label: '已下架'},
        {value: '6', label: '已售罄'},
        {value: '7', label: '已删除'},
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        content: null,
        createtime: null,
        defaultimage: null,
        goodsno: null,
        name: null,
        status: null,
        goodschannelId: null,
        merchantId: null,
        defaultprice: null,
        marketprice: null,
        qualificationimage: null,
        store: null,
        applytime: null,
        checknote: null,
        checktime: null,
        recommend: null,
        salesvolume: null,
        postage: null,
        postagetype: null,
        havesku: null,
        attributechannelId: null,
        gram: null,
        freighttemplateId: null,
        bargainbegintime: null,
        bargainendtime: null,
        bargainprice: null,
        bargainstore: null,
        marketingtype: null,
        begindateofvalidity: null,
        enddateofvalidity: null,
        bargainstatus: null,
        bargainsalesvolume: null,
        seckillprice: null,
        seckillsalesvolume: null,
        seckillstatus: null,
        seckillstore: null,
        seckillsessionId: null,
        presellprice: null,
        presellretainagepaybegintime: null,
        presellretainagepayendtime: null,
        presellsalesvolume: null,
        presellstatus: null,
        presellsubscriptionpaybegintime: null,
        presellsubscriptionpayendtime: null,
        groupbookingbegintime: null,
        groupbookingcondition: null,
        groupbookingendtime: null,
        groupbookinglimit: null,
        groupbookingprice: null,
        groupbookingsalesvolume: null,
        groupbookingstatus: null,
        groupbookingtotal: null,
        groupbookingstore: null,
        issupplier: null,
        brandId: null,
        affiliatedunitvalue: null,
        havemultiunit: null,
        ultimateunitvalue: null,
        affiliatedunitId: null,
        ultimateunitId: null,
        unitId: null,
        supplierpostage: null,
        supplierpostagetype: null,
        supplierfreighttemplateId: null,
        recommendsupplier: null,
        isissuingtype: null,
        issuinggoodsId: null,
        recommendtime: null,
        sellstatus: null,
        rankno: null,
        dishcount: null,
        provideballoon: null,
        providechair: null,
        provideclean: null,
        tableservicenum: null,
        tablemax: null,
        provideinvoice: null,
        nomaterial: null,
        nomaterialprice: null,
        withmaterial: null,
        withmaterialprice: null,
        goodstype: null,
        providebreakfast: null,
        roomtype: null,
        shopcostprice: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        defaultprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        marketprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        store: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        recommend: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        salesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        postage: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        postagetype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        havesku: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        gram: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        marketingtype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        bargainstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        bargainsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        seckillstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        presellstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingcondition: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookinglimit: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingprice: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingsalesvolume: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingstatus: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingtotal: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        groupbookingstore: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        issupplier: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        affiliatedunitvalue: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        havemultiunit: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        ultimateunitvalue: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        supplierpostage: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        supplierpostagetype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        recommendsupplier: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        isissuingtype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    const goodsId = this.$route.query && this.$route.query.goodsId;
    this.goodsId = goodsId;
    this.getGoodsDetail();
  },
  methods: {
    getGoodsDetail(){
      this.loading = true;
      let queryDto = {id:this.goodsId};
      goodsDetail(queryDto).then(response => {
        const detail = response.data;
        this.goodsDetail = detail;
        console.log(detail.defaultimage);
        this.goodsImageList = detail.goodsImageList || [];
        this.goodsParamsList = detail.goodsParamsList || [];
        this.loading = false;
      });
    },


    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        content: null,
        createtime: null,
        defaultimage: null,
        goodsno: null,
        name: null,
        status: 0,
        goodschannelId: null,
        merchantId: null,
        defaultprice: null,
        marketprice: null,
        qualificationimage: null,
        store: null,
        applytime: null,
        checknote: null,
        checktime: null,
        recommend: null,
        salesvolume: null,
        postage: null,
        postagetype: null,
        havesku: null,
        attributechannelId: null,
        gram: null,
        freighttemplateId: null,
        bargainbegintime: null,
        bargainendtime: null,
        bargainprice: null,
        bargainstore: null,
        marketingtype: null,
        begindateofvalidity: null,
        enddateofvalidity: null,
        bargainstatus: 0,
        bargainsalesvolume: null,
        seckillprice: null,
        seckillsalesvolume: null,
        seckillstatus: 0,
        seckillstore: null,
        seckillsessionId: null,
        presellprice: null,
        presellretainagepaybegintime: null,
        presellretainagepayendtime: null,
        presellsalesvolume: null,
        presellstatus: 0,
        presellsubscriptionpaybegintime: null,
        presellsubscriptionpayendtime: null,
        groupbookingbegintime: null,
        groupbookingcondition: null,
        groupbookingendtime: null,
        groupbookinglimit: null,
        groupbookingprice: null,
        groupbookingsalesvolume: null,
        groupbookingstatus: 0,
        groupbookingtotal: null,
        groupbookingstore: null,
        issupplier: null,
        brandId: null,
        affiliatedunitvalue: null,
        havemultiunit: null,
        ultimateunitvalue: null,
        affiliatedunitId: null,
        ultimateunitId: null,
        unitId: null,
        supplierpostage: null,
        supplierpostagetype: null,
        supplierfreighttemplateId: null,
        recommendsupplier: null,
        isissuingtype: null,
        issuinggoodsId: null,
        recommendtime: null,
        sellstatus: "0",
        rankno: null,
        dishcount: null,
        provideballoon: null,
        providechair: null,
        provideclean: null,
        tableservicenum: null,
        tablemax: null,
        provideinvoice: null,
        nomaterial: null,
        nomaterialprice: null,
        withmaterial: null,
        withmaterialprice: null,
        goodstype: null,
        providebreakfast: null,
        roomtype: null,
        shopcostprice: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGoods(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //批量审核通过
    handleAudit(auditType) {
      const ids = this.ids;
      let longIdList = [];
      this.ids.forEach(item=>{
        longIdList.push(item);
      })
      const auditDto = {
        longIdList,
        optType:auditType
      }
      let message = "是否确认审核";
      if(auditType==='Y'){
        message+="通过选择的"+ids.length+"条商品信息";
      }
      if(auditType==='N'){
        message+="不通过选择的"+ids.length+"条商品信息";
      }
      this.$modal.confirm(message).then(function() {
        return auditGoods(auditDto);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    //设置商品上架、下架
    handleSellStatus(row,optType){
      let longIdList = [];
      longIdList.push(row.id);
      const optDto = {
        longIdList,
        optType
      }
      let message = "是否确认";
      if(optType==='Y'){
        message+='上架名称为"'+row.name+'"的商品？';
      }
      if(optType==='N'){
        message+='下架名称为"'+row.name+'"的商品？';
      }
      this.$modal.confirm(message).then(function() {
        return changeSellStatus(optDto);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    //跳转到商品详情页面
    handleDetail(row){

    },
  }
};
</script>
